<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        function fn(num) {
        var arr = [1, 3, 5, 7, 9]
      
        var index 
        for (var i = 0; i < arr.length; i++) {
            if (num < arr[i]) {
                index = i
                break
            }
        }
        arr.splice(index, 0, num)
        return arr
    }

    fn(8)
    console.log(fn(8));
    </script>
</body>
</html>